/**
 * Created by Administrator on 2017/3/13 0013.
 */


function PSP(ImageName) {
    return new PIXI.Sprite(resource["images/" + ImageName + ".png"].texture);
}
Main = {
    Create: function () {
        var main = {};
        var stage = new PIXI.Container();
        var renderer = new PIXI.CanvasRenderer(256, 256, {antialias: true, transparent: true});
        renderer.view.style.border = "0px dashed black";
        renderer.resize(666, 666);
        renderer.backgroundColor = 0x000000;

        var container = document.createElement("div");
        container.id = "Layer2D";
        container.style.position = "absolute";
        document.body.appendChild(container);
        container.appendChild(renderer.view);


        document.addEventListener('Start', Start);
        function Start() {
            setup();
            document.addEventListener("ScreenChange", resizeHandler);
            //页面适配
            function resizeHandler(e){
                if(e.detail=="main") {
                    resize();
                }
            }
            function resize() {
                var w, h, setW, setH;
                setW = pixiStageW;
                setH = pixiStageH;

                if (screenType == "hor") {

                    w = windowLength2;
                    h = windowLength1;
                    renderer.resize(w, h);
                    stage.scale.x = ( h / setH < w / setW) ? (w / setW) : ( h / setH);
                    stage.scale.y = stage.scale.x;
                    stage.x = (w - setW * stage.scale.x) * .5;
                    stage.y = (h - setH * stage.scale.y) * .5;

                }
                else {
                    w = windowLength1;
                    h = windowLength2;
                    renderer.resize(w, h);
                    stage.scale.x = ( h / setH < w / setW) ? (w / setW) : ( h / setH);
                    stage.scale.y = stage.scale.x;
                    stage.x = (w - setW * stage.scale.x) * .5;
                    stage.y = (h - setH * stage.scale.y) * .5;
                }

                // alert("stage.y"+stage.y)
            }
        }



        var CC = ControlCenter.Create();
        stage.addChild(CC.ReturnWhole());
        //程序开始
        function setup() {
            //控制页面
            console.log("RealStart");
            CC.Go();

            //加载页面在正式页面之上

        };


        //渲染层
        gameLoop();
        function gameLoop() {
            requestAnimationFrame(gameLoop);
            CC.DoIt();
            //Render The Stage
            renderer.render(stage);

        }

        return main;
    }
}
